package com.driver.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
import com.driver.system.controller.form.SearchWalletIncomeByPageForm;
import com.driver.system.controller.form.SearchWalletPaymentByPageForm;
import com.driver.system.service.WalletIncomeService;
import com.driver.system.service.WalletPaymentService;
import com.driver.system.util.PageUtils;
import com.driver.system.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/wallet/payment")
@Tag(name = "WalletPaymentController", description = "司机钱包出账Web接口")
public class WalletPaymentController {
    @Resource
    private WalletPaymentService walletPaymentService;

    @PostMapping("/searchWalletPaymentByPage")
    @Operation(summary = "分页查询钱包出账数据")
    @SaCheckPermission(value = {"ROOT", "USER:SELECT"}, mode = SaMode.OR)
    public R searchWalletPaymentByPage(@Valid @RequestBody SearchWalletPaymentByPageForm form){
        int page = form.getPage();
        int length = form.getLength();
        int start = (page - 1) * length;
        Map param = BeanUtil.beanToMap(form);
        param.put("start", start);
        PageUtils pageUtils = walletPaymentService.searchWalletPaymentByPage(param);
        return R.ok().put("result", pageUtils);
    }
}
